package com.dmx.fw.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.dmx.fw.bean.PageInfo;
import com.dmx.fw.bean.QueryInfoBean;
import com.dmx.fw.component.commonquery.QueryScriptDef;
import com.dmx.fw.service.interfaces.QueryService;
import com.dmx.fw.service.interfaces.QueryServiceUsing;

public class QueryServiceUsingImpl implements QueryServiceUsing {

	@SuppressWarnings("unchecked")
	@Override
	public List<Object[]> findQureyObjects(String busiId,String orderBy,String orderMode,String[][] datas, int currentPage,int pageSize) {
		// TODO Auto-generated method stub
		Map<String,String> paramsMap = null;
		if(datas!=null){
			paramsMap = new HashMap<String,String>();
			for(int i=0;i<datas.length;i++){
				paramsMap.put(datas[i][0], datas[i][1]);
			}
		}
		PageInfo pageInfo = new PageInfo();
        if(pageSize>0){
        	pageInfo.setPageSize(pageSize);
        }
		QueryInfoBean queryInfoBean = (QueryInfoBean) QueryScriptDef.getQueryInfo(busiId);
		String orderByStr =" order by ";
		if (orderBy != null && !"".equals(orderBy)){
			orderByStr=orderByStr + orderBy;
			if ( orderMode!= null && !"".equals(orderMode)){
				orderByStr = orderByStr + " " + orderMode;
			}
			queryInfoBean.setOrderByScript(orderByStr);
		}
		
		if(currentPage>0){
			pageInfo.setCurrentPageNo(currentPage);
		}
		pageInfo = queryService.queryData(queryInfoBean, paramsMap, pageInfo, "LIST");
		return pageInfo.getSearchResult();

	}

	
	QueryService queryService;
	QueryScriptDef queryScriptDef;

	public void setQueryService(QueryService queryService) {
		this.queryService = queryService;
	}

	public void setQueryScriptDef(QueryScriptDef queryScriptDef) {
		this.queryScriptDef = queryScriptDef;
	}
	
	

}
